package com.srd.phone.mvp.presenters;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.srd.phone.application.HttpStringRequest;
import com.srd.phone.mvp.interfaces.IBaseView;

import java.util.HashMap;
import java.util.Map;

public class ModifyPresenter extends BasePresenter {

    public ModifyPresenter(RequestQueue requestQueue, IBaseView iView0) {
        super(requestQueue,iView0);
    }

    /**
     * 修改邮箱
     */
    public void requestData(final String url, final String t, final String em) {
        HttpStringRequest request = new HttpStringRequest(Request.Method.POST, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                iView.get().returnData(url, response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                iView.get().onError(url, error);
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<>();
                map.put("t", t);
                map.put("em", em);
                return map;
            }
        };
        request.setTag(url);
        requestQueue.add(request);
    }

    /**
     * 修改手机号
     */
    public void requestData2(final String url, final String t, final String ph) {
        HttpStringRequest request = new HttpStringRequest(Request.Method.POST, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                iView.get().returnData(url, response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                iView.get().onError(url, error);
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<>();
                map.put("t", t);
                map.put("ph", ph);
                return map;
            }
        };
        request.setTag(url);
        requestQueue.add(request);
    }

    /**
     * 修改密码
     */
    public void requestData3(final String url, final String t, final String oPwd, final String nPwd) {
        HttpStringRequest request = new HttpStringRequest(Request.Method.POST, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                iView.get().returnData(url, response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                iView.get().onError(url, error);
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<>();
                map.put("t", t);
                map.put("oPwd", oPwd);
                map.put("nPwd", nPwd);
                return map;
            }
        };
        request.setTag(url);
        requestQueue.add(request);
    }

}